package com.zqxq.lottery.api.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "wechat-config")
@Component("wechatConfig")
@Data
@Slf4j
public class WechatConfig implements InitializingBean {

    public static final String CONFIG_EXCEPTION = "配置参数不能为null";
    private String serverUrl;
    private String drawCashUrl;
    private String appId;
    private String appSecret;
    private String mchId;
    private String key;
    private String certPath;
    private String notifyUrl;
    @Override
    public void afterPropertiesSet() throws Exception {
        if(null == serverUrl || "".equals(serverUrl.trim())) {
            throw new IllegalArgumentException("serverUrl"+CONFIG_EXCEPTION);
        }
        if(null == drawCashUrl || "".equals(drawCashUrl.trim())) {
            throw new IllegalArgumentException("drawCashUrl"+CONFIG_EXCEPTION);
        }
        if(null == appId || "".equals(appId.trim())) {
            throw new IllegalArgumentException("appId"+CONFIG_EXCEPTION);
        }
        if(null == appSecret || "".equals(appSecret.trim())) {
            throw new IllegalArgumentException("appSecret"+CONFIG_EXCEPTION);
        }

        if(null == mchId || "".equals(mchId.trim())) {
            throw new IllegalArgumentException("mchId"+CONFIG_EXCEPTION);
        }
        if(null == key || "".equals(key.trim())) {
            throw new IllegalArgumentException("key"+CONFIG_EXCEPTION);
        }
        if(null == certPath || "".equals(certPath.trim())) {
            throw new IllegalArgumentException("certPath"+CONFIG_EXCEPTION);
        }
        if(null == notifyUrl || "".equals(notifyUrl.trim())) {
            throw new IllegalArgumentException("notifyUrl"+CONFIG_EXCEPTION);
        }
    }

}
